<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
    <div class="container">
        <a href="{{ url_for('views.static_html', route='/') }}" class="navbar-brand">
            {% if Configs.ctf_logo %}
            <img class="img-responsive ctf_logo" src="{{ url_for('views.files', path=Configs.ctf_logo) }}" height="25"
                 alt="{{ Configs.ctf_name }}">
            {% else %}
            {{ Configs.ctf_name }}
            {% endif %}
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#base-navbars"
                aria-controls="base-navbars" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="base-navbars">
            <ul class="navbar-nav mr-auto">
                {% for page in Plugins.user_menu_pages %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ page.route }}">{{ page.title }}</a>
                </li>
                {% endfor %}

                {% if Configs.account_visibility != 'admins' %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('users.listing') }}">{{ 'Users' if en else '用户' }}</a>
                </li>
                {% if Configs.user_mode == 'teams' %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('teams.listing') }}">{{ 'Teams' if en else '队伍' }}</a>
                </li>
                {% endif %}
                {% endif %}

                {% if Configs.account_visibility != 'admins' and Configs.score_visibility != 'admins' %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('scoreboard.listing') }}">{{ 'Scoreboard' if en else '计分板' }}</a>
                </li>
                {% endif %}

                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('challenges.listing') }}">{{ 'Challenges' if en else '题目' }}</a>
                </li>
            </ul>

            <hr class="d-sm-flex d-md-flex d-lg-none">

            <ul class="navbar-nav ml-md-auto d-block d-sm-flex d-md-flex">
                <li class="nav-item">
                    <a class="nav-link" href="" onclick="ChangeLanguage()">
                                <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'English' if en else '简体中文' }}">
                                    <i class="fas fa-language d-none d-md-block d-lg-none"></i>
                                </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                    <i class="fas fa-language pr-1"></i>{{ 'English' if en else '简体中文' }}
                                </span>
                    </a>
                </li>
                {% if authed() %}
                {% if is_admin() %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('admin.view') }}">
                                <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Admin Panel' if en else '管理面板' }}">
                                    <i class="fas fa-wrench d-none d-md-block d-lg-none"></i>
                                </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                    <i class="fas fa-wrench pr-1"></i>{{ 'Admin Panel' if en else '管理面板' }}
                                </span>
                    </a>
                </li>
                {% endif %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('views.notifications') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Notifications' if en else '平台通知' }}">
                                <i class="fas fa-bell d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-bell pr-1"></i>
                                <span class="badge badge-pill badge-danger badge-notification"></span>
                                {{ 'Notifications' if en else '平台通知' }}
                            </span>
                    </a>
                </li>
                {% if Configs.user_mode == "teams" %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('teams.private') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Team' if en else '队伍纪录' }}">
                                <i class="fas fa-users d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-users pr-1"></i>{{ 'Team' if en else '队伍纪录' }}
                            </span>
                    </a>
                </li>
                {% endif %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('users.private') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Profile' if en else '个人纪录' }}">
                                <i class="fas fa-user-circle d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-user-circle pr-1"></i>{{ 'Profile' if en else '个人纪录' }}
                            </span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('views.settings') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Settings' if en else '设置' }}">
                                <i class="fas fa-cogs d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-cogs pr-1"></i>{{ 'Settings' if en else '设置' }}
                            </span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('auth.logout') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Logout' if en else '注销' }}">
                                <i class="fas fa-sign-out-alt d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-sign-out-alt pr-1"></i><span class="d-lg-none">{{ 'Logout' if en else '注销' }}</span>
                            </span>
                    </a>
                </li>
                {% else %}
                {% if registration_visible() %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('auth.register') }}">
                                <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Register' if en else '注册' }}">
                                    <i class="fas fa-user-plus d-none d-md-block d-lg-none"></i>
                                </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                    <i class="fas fa-user-plus pr-1"></i>{{ 'Register' if en else '注册' }}
                                </span>
                    </a>
                </li>
                {% endif %}
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('auth.login') }}">
                            <span class="d-block" data-toggle="tooltip" data-placement="bottom" title="{{ 'Login' if en else '登陆' }}">
                                <i class="fas fa-sign-in-alt d-none d-md-block d-lg-none"></i>
                            </span>
                        <span class="d-sm-block d-md-none d-lg-block">
                                <i class="fas fa-sign-in-alt pr-1"></i>{{ 'Login' if en else '登陆' }}
                            </span>
                    </a>
                </li>
                {% endif %}
            </ul>
        </div>
    </div>
    <script>
        // 切换语言并存储在cookie中
        function ChangeLanguage()
        {
            // 这里你可以添加其他的切换语言的逻辑，比如更新页面内容等
            const currentLanguage = getLanguage();
            const newLanguage = currentLanguage === 'zh' ? 'en' : 'zh';
            setLanguage(newLanguage);
        }

        // 获取当前语言
        function getLanguage() {
            const language = getCookie('Scr1wCTFdLanguage');
            if (language == null)
            {
                setLanguage('zh');
            }
            return language || 'zh'; // 默认为中文
        }

        // 设置语言并存储在cookie中
        function setLanguage(language) {
            setCookie('Scr1wCTFdLanguage', language, 365 * 10); // 存储10年，近乎永不过期
        }

        // 获取cookie
        function getCookie(name) {
            const cookies = document.cookie.split('; ');
            for (const cookie of cookies) {
                const [cookieName, cookieValue] = cookie.split('=');
                if (cookieName === name) {
                    return decodeURIComponent(cookieValue);
                }
            }
            return null;
        }

        // 设置cookie
        function setCookie(name, value, days) {
            const date = new Date();
            date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
            const expires = `expires=${date.toUTCString()}`;
            document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}; path=/`;
        }

    </script>
</nav>
